package com.mingqijia.gassafety.console.controller;

import com.gap.basic.base.CommonResponse;
import com.mingqijia.gassafety.shared.constant.OperateRecordEnum;
import com.mingqijia.gassafety.webserver.request.DeviceSolenoidRequest;
import com.mingqijia.gassafety.webserver.request.SolenoidRecordRequest;
import com.mingqijia.gassafety.webserver.request.UnbindSolenoidRequest;
import com.mingqijia.gassafety.webserver.service.DeviceSolenoidService;
import com.mingqijia.gassafety.shared.log.LogRecord;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author zhangfei
 * @version 1.0.0
 * @ClassName DeviceSolenoidController.java
 * @Description 客户、电磁阀关联
 * @createTime 2023年08月21日
 */
@RestController
@Api(tags = "客户、电磁阀关联")
@RequestMapping("/business/v1/DeviceSolenoid")
@Slf4j
public class DeviceSolenoidController {


    @Autowired
    private DeviceSolenoidService deviceSolenoidService;

    /**
     * 设备电磁阀操作
     *
     * @param request
     * @return
     */
    @LogRecord(operateType = OperateRecordEnum.OPERATE_TYPE_13, detail = "'【设备号：' + #request.imei +'】'")
    @PostMapping("updateDeviceSolenoid")
    @ApiOperation(value = "设备电磁阀操作")
    public CommonResponse<Object> updateDeviceSolenoid(@RequestBody @Valid DeviceSolenoidRequest request) {
        deviceSolenoidService.updateDeviceSolenoid(request);
        return CommonResponse.success("success");
    }

    /**
     * 解除电磁阀关联
     * @param request
     * @return
     */
    @LogRecord(operateType = OperateRecordEnum.OPERATE_TYPE_15, detail = "'【设备号：' + #request.imei +'】解除'")
    @PostMapping("unbindSolenoid")
    @ApiOperation(value = "设备电磁阀解绑")
    public CommonResponse<Object> unbindSolenoid(@RequestBody @Valid UnbindSolenoidRequest request) {
        deviceSolenoidService.unbindSolenoid(request);
        return CommonResponse.success("success");
    }


    /**
     * 电磁阀操作记录
     *
     * @param request
     * @return
     */
    @PostMapping("deviceSolenoidRecord")
    @ApiOperation(value = "设备电磁阀操作记录")
    public CommonResponse<Object> deviceSolenoidRecord(@RequestBody @Valid SolenoidRecordRequest request) {
        return CommonResponse.success(deviceSolenoidService.deviceSolenoidRecord(request));
    }
}